package com.ssd.controller.inner;

import cn.hutool.core.bean.BeanUtil;


import com.ssd.api.payment.NativePayApi;
import com.ssd.api.payment.dto.request.NativePayReqDTO;
import com.ssd.api.payment.dto.response.NativePayResDTO;
import com.ssd.model.domain.Trading;
import com.ssd.service.NativePayService;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Native支付方式Face接口：商户生成二维码，用户扫描支付
 *
 * @author itcast
 */
@Validated
@RestController("innerNativePayController")
@Api(tags = "内部接口 - Native支付")
@RequestMapping("/inner/native")
public class NativePayController  implements NativePayApi {

    //二维码支付服务接口
    @Resource
    private NativePayService nativePayService;



    /***
     * 扫码支付，收银员通过收银台或商户后台调用此接口，生成二维码后，展示给用户，由用户扫描二维码完成订单支付。
     * @param nativePayDTO 扫码支付提交参数
     * @return 扫码支付响应数据，其中包含二维码路径
     */
    @PostMapping
    @ApiOperation(value = "统一收单线下交易", notes = "统一收单线下交易")
    public NativePayResDTO createDownLineTrading(@ApiParam(value = "扫码支付提交参数") @RequestBody NativePayReqDTO nativePayDTO) {
        // 将请求参数转换为交易实体
        Trading tradingEntity = BeanUtil.toBean(nativePayDTO, Trading.class);
        // 调用服务层处理线下交易逻辑
        Trading trading = this.nativePayService.createDownLineTrading(nativePayDTO.isChangeChannel(), tradingEntity);
        // 将交易结果转换为响应DTO并返回
        return BeanUtil.toBean(trading, NativePayResDTO.class);
    }


}

